home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / Developer Documentation / Recipes, Tech Notes & Articles / Recipes / Undo Recipes < prev   
Encoding:
Text File  |  1996-04-29  |  3.1 KB  |  90 lines  |  [TEXT/ttxt]

  1. Undo Recipes
  2. By The OpenDoc™ Design Team
  3. 16 April, 1996
  4.  
  5.  
  6. © 1993-1996  Apple Computer, Inc. All Rights Reserved.
  7. Apple, the Apple logo, and Macintosh are registered trademarks of Apple Computer, Inc.
  8. Mac and OpenDoc are trademarks of Apple Computer, Inc.
  9.  
  10.  
  11. Supplementary information to the OpenDoc Programmer's Guide.
  12.  
  13. Sample Code
  14.  
  15. Adding a single action to the Undo history
  16.  
  17.  // CREATE UNDO MENU ITEM TEXT
  18.  ODIText* undoActionName = CreateIText("Undo My Action");
  19.  ODIText* redoActionName = CreateIText("Redo My Action");
  20.  
  21.  // CREATE A STRUCTURE TO HOLD DATA ABOUT ACTION
  22.  MyUndoInfo* uInfo = (MyUndoInfo*)AllocMem(sizeof(MyUndoInfo));
  23.  // ADD DATA TO STRUCTURE (TASK SPECIFIC)
  24.  uInfo->someData = …
  25.  
  26.  MyGetSession()->GetUndo()->AddActionToHistory(somSelf,
  27.                                            (ODActionData)uInfo,
  28.                                            kODSingleAction,
  29.                                            undoMenuText,
  30.                                            redoMenuText);
  31.  
  32.  DeleteIText(undoActionName );
  33.  DeleteIText(redoActionName );
  34.  
  35. Handling the Undo and Redo menu items (Parts don't have to do this. This information is for container application writers.)
  36.  
  37. Container applications should manage the Undo and Redo menu items and should call Undo and Redo when they are selected. Here's some sample code for the display and activation of these menu items:
  38.  
  39.  ODUndo*         undo = MyGetSession()->GetUndo(ev);
  40.  ODPart*         part;
  41.  ODActionData    actionData;
  42.  ODActionType    actionType;
  43.  ODName*         actionLabel;
  44.  
  45.  // CREATE EMPTY ITEXT STRUCTURE TO BE COPIED INTO
  46.  actionLabel = CreateIText(UCHAR_MAX);
  47.  
  48.  // LOOK AT THE STACK
  49.  if (undo->PeekUndoHistory(ev, &part, &actionData, &actionType,
  50.         actionLabel))
  51.  {
  52.   fMenuBar->EnableCommand(ev, kODCommandUndo, kODTrue);
  53.   fMenuBar->SetItemString(ev, kODCommandUndo, actionLabel);
  54.  }
  55.  else
  56.  {
  57.   fMenuBar->EnableCommand(ev, kODCommandUndo, kODFalse);
  58.   this->ResetUndoText(editMenu);
  59.  }
  60.  
  61.  DeleteIText(actionLabel);
  62.  
  63.  // SIMILARLY FOR REDO
  64.  …
  65.  
  66. (ResetUndoText is a function that sets the text of the Undo menu item to the default string.)
  67.  
  68. Nesting transactions
  69.  
  70. Multi-stage Undo can be nested, that is, it is not an error if another begin action is placed in the action history before the current transaction is finished. Of course there must be a corresponding end action for end begin action and the nested transaction must be completed nested inside the outer transaction (no overlapping). When calling AbortCurrentTransaction, any actions associated with nested transactions as well as those associated with the current transaction are also cleared.
  71.  
  72. AbortCurrentTransaction
  73.  
  74. When AbortCurrentTransaction is called, the actions which are cleared trigger calls to the DisposeActionState methosd of the parts associated with the actions. Before this happens, the parts should also be asked to undo the actions via a call to the parts' UndoAction method. In OpenDoc 1.0.4, this does not occur. This bug will be fixed in a future release of OpenDoc.
  75.  
  76. Order of action disposal
  77.  
  78. Parts should not count on the order in which DisposeActionState will be called for actions that they have placed in the action history.
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.